package com.bitdf.txing.seckill.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bitdf.txing.common.utils.PageUtils;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.seckill.entity.SeckillSkuRelationEntity;
import com.bitdf.txing.seckill.service.SeckillSkuRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 秒杀活动商品关联
 *
 * @author lizhiwei
 * @email sunlightcs@gmail.com
 * @date 2022-05-16 21:36:42
 */
@RestController
@RequestMapping("${txing.request.path.seckill}/coupon/seckillskurelation")
public class SeckillSkuRelationController {
    @Autowired
    private SeckillSkuRelationService seckillSkuRelationService;

    /**
     * 分页查询
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillSkuRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 获取 秒杀商品信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SeckillSkuRelationEntity seckillSkuRelation = seckillSkuRelationService.getById(id);

        return R.ok().put("seckillSkuRelation", seckillSkuRelation);
    }

    /**
     * 添加秒杀商品信息
     */
    @RequestMapping("/save")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:relation:add")
    public R save(@RequestBody SeckillSkuRelationEntity seckillSkuRelation){
		seckillSkuRelationService.save(seckillSkuRelation);

        return R.ok();
    }

    /**
     * 修改 秒杀商品信息
     */
    @RequestMapping("/update")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:relation:update")
    public R update(@RequestBody SeckillSkuRelationEntity seckillSkuRelation){
		seckillSkuRelationService.updateById(seckillSkuRelation);

        return R.ok();
    }

    /**
     * 删除 秒杀商品信息
     */
    @RequestMapping("/delete")
    @SaCheckLogin
    @SaCheckPermission("mall:seckill:sku:relation:delete")
    public R delete(@RequestBody Long[] ids){
		seckillSkuRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
